<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

		<title>地址管理</title>

		<link href="/Public/one/AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
		<link href="/Public/one/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css">

		<link href="/Public/one/css/personal.css" rel="stylesheet" type="text/css">
		<link href="/Public/one/css/addstyle.css" rel="stylesheet" type="text/css">
		<script src="/Public/one/AmazeUI-2.4.2/assets/js/jquery.min.js" type="text/javascript"></script>
		<script src="/Public/one/AmazeUI-2.4.2/assets/js/amazeui.js"></script>

	</head>

	<body>
		<!--头 -->
		<header>
			<article>
				<div class="mt-logo">
					<!--顶部导航条 -->
					<include file="Public/tpl/hometop.html"/>
					</div>
				</div>
			</article>
		</header>

		<div class="nav-table">
			<div class="long-title"><span class="all-goods">全部分类</span></div>
			<div class="nav-cont">
				<ul>
					<li class="index"><a href="#">首页</a></li>
					<li class="qc"><a href="#">闪购</a></li>
					<li class="qc"><a href="#">限时抢</a></li>
					<li class="qc"><a href="#">团购</a></li>
					<li class="qc last"><a href="#">大包装</a></li>
				</ul>
				<div class="nav-extra">
					<i class="am-icon-user-secret am-icon-md nav-user"></i><b></b>我的福利
					<i class="am-icon-angle-right" style="padding-left: 10px;"></i>
				</div>
			</div>
		</div>
		<b class="line"></b>

		<div class="center">
			<div class="col-main">
				<div class="main-wrap">

					<div class="user-address">
						<!--标题 -->
						<div class="am-cf am-padding">
							<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">地址管理</strong> / <small>Address&nbsp;list</small></div>
						</div>
						<hr/>
						<ul class="am-avg-sm-1 am-avg-md-3 am-thumbnails">

						<!-- 	<li class="user-addresslist defaultAddr">
								<span class="new-option-r"><i class="am-icon-check-circle"></i>默认地址</span>
								<p class="new-tit new-p-re">
									<span class="new-txt">小叮当</span>
									<span class="new-txt-rd2">159****1622</span>
								</p>
								<div class="new-mu_l2a new-p-re">
									<p class="new-mu_l2cw">
										<span class="title">地址：</span>
										<span class="province">湖北</span>省
										<span class="city">武汉</span>市
										<span class="dist">洪山</span>区
										<span class="street">雄楚大道666号(中南财经政法大学)</span></p>
								</div>
								<div class="new-addr-btn">
									<a href="#"><i class="am-icon-edit"></i>编辑</a>
									<span class="new-addr-bar">|</span>
									<a href="javascript:void(0);" onclick="delClick(this);"><i class="am-icon-trash"></i>删除</a>
								</div>
							</li>

							<li class="user-addresslist">
								<span class="new-option-r"><i class="am-icon-check-circle"></i>设为默认</span>
								<p class="new-tit new-p-re">
									<span class="new-txt">小叮当</span>
									<span class="new-txt-rd2">159****1622</span>
								</p>
								<div class="new-mu_l2a new-p-re">
									<p class="new-mu_l2cw">
										<span class="title">地址：</span>
										<span class="province">湖北</span>省
										<span class="city">武汉</span>市
										<span class="dist">洪山</span>区
										<span class="street">雄楚大道666号(中南财经政法大学)</span></p>
								</div>
								<div class="new-addr-btn">
									<a href="#"><i class="am-icon-edit"></i>编辑</a>
									<span class="new-addr-bar">|</span>
									<a href="javascript:void(0);" onclick="delClick(this);"><i class="am-icon-trash"></i>删除</a>
								</div>
							</li>
							<li class="user-addresslist">
								<span class="new-option-r"><i class="am-icon-check-circle"></i>设为默认</span>
								<p class="new-tit new-p-re">
									<span class="new-txt">小叮当</span>
									<span class="new-txt-rd2">159****1622</span>
								</p>
								<div class="new-mu_l2a new-p-re">
									<p class="new-mu_l2cw">
										<span class="title">地址：</span>
										<span class="province">湖北</span>省
										<span class="city">武汉</span>市
										<span class="dist">洪山</span>区
										<span class="street">雄楚大道666号(中南财经政法大学)</span></p>
								</div>
								<div class="new-addr-btn">
									<a href="#"><i class="am-icon-edit"></i>编辑</a>
									<span class="new-addr-bar">|</span>
									<a href="javascript:void(0);" onclick="delClick(this);"><i class="am-icon-trash"></i>删除</a>
								</div>
							</li> -->
						</ul>
						<div class="clear"></div>
						<a class="new-abtn-type" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0}">添加新地址</a>
						<!--例子-->
<div class="am-modal am-modal-no-btn" id="doc-modal-1">

	<div class="add-dress">

		<!--标题 -->
		<div class="am-cf am-padding">
			<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add&nbsp;address</small></div>
		</div>
		<hr/>

		<div class="am-u-md-12 am-u-lg-8" style="margin-top: 20px;">
			<form class="am-form am-form-horizontal" >

				<div class="am-form-group">
					<label for="user-name" class="am-form-label">收货人</label>
					<div class="am-form-content">
						<input type="text" id="user-name" placeholder="收货人">
					</div>
				</div>

				<div class="am-form-group">
					<label for="user-phone" class="am-form-label">手机号码</label>
					<div class="am-form-content">
						<input id="user-phone" placeholder="手机号必填" type="email">
					</div>
				</div>
				<div class="am-form-group">
					<label for="user-address" class="am-form-label">所在地</label>
					<div class="am-form-content address">
						<select data-am-selected id="province" onchange="citySelect(this)" name="province">
						<option value="a">省</option>
							
						</select>
						<select data-am-selected id="city"  onchange="townSelect(this)">
							<option value="a">市</option>
							
						</select>
						<select data-am-selected id="town">
							<option value="a">地方</option>
						</select>
					</div>
				</div>

				<div class="am-form-group">
					<label for="user-intro" class="am-form-label">详细地址</label>
					<div class="am-form-content">
						<textarea class="" rows="3" id="user-intro" placeholder="输入详细地址"></textarea>
						<small>100字以内写出你的详细地址...</small>
					</div>
				</div>

				<div class="am-form-group">
					<div class="am-u-sm-9 am-u-sm-push-3">
						<a class="am-btn am-btn-danger" onclick="addAddress()">保存</a>
						<a href="javascript: void(0)" class="am-close am-btn am-btn-danger" data-am-modal-close onclick="cencle(this)">取消</a>
					</div>
				</div>
			</form>
		</div>

		</div>

	</div>

</div>

					<script type="text/javascript">
						$(document).ready(function() {							
							$(".new-option-r").click(function() {
								$(this).parent('.user-addresslist').addClass("defaultAddr").siblings().removeClass("defaultAddr");
							});
							
							var $ww = $(window).width();
							if($ww>640) {
								$("#doc-modal-1").removeClass("am-modal am-modal-no-btn")
							}
							
						})
					</script>

					<div class="clear"></div>

				</div>
				<!--底部-->
				<div class="footer">
					<div class="footer-hd">
						<p>
							<a href="#">恒望科技</a>
							<b>|</b>
							<a href="#">商城首页</a>
							<b>|</b>
							<a href="#">支付宝</a>
							<b>|</b>
							<a href="#">物流</a>
						</p>
					</div>
					<div class="footer-bd">
						<p>
							<a href="#">关于恒望</a>
							<a href="#">合作伙伴</a>
							<a href="#">联系我们</a>
							<a href="#">网站地图</a>
							<em>© 2015-2025 Hengwang.com 版权所有</em>
						</p>
					</div>
				</div>
			</div>

			<include file="Public/tpl/homeleft.html"/>
		</div>
	<script type="text/html" id="showAddress">
		<%for(var i=0;i<data.length;i++){%>
			<%if(data[i].default=='是'){%>
				<li class="user-addresslist defaultAddr">
				<%}else{%>
				<li class="user-addresslist ">
			<%}%>
				<span class="new-option-r" alt="<%=data[i].id%>" onclick="default1(this)"><i class="am-icon-check-circle"></i>设为默认</span>
				<p class="new-tit new-p-re">
					<span class="new-txt"><%=data[i].name%></span>
					<span class="new-txt-rd2"><%=data[i].phone%></span>
				</p>
				<div class="new-mu_l2a new-p-re">
					<p class="new-mu_l2cw">
					<%var address=data[i].address%>
						<span class="title">地址：</span>
						<span class="province"><%=address[0]%></span>
						<span class="city"><%=address[1]%></span>
						<span class="dist"><%=address[2]%></span>
						<span class="street"><%=address[3]%></span></p>
				</div>
				<div class="new-addr-btn">
					<a  onclick="chaClick(this)" alt="<%=data[i].id%>"><i class="am-icon-edit"></i>编辑</a>
					<span class="new-addr-bar">|</span>
					<a href="javascript:void(0);" onclick="delClick(this)" alt="<%=data[i].id%>"; ><i class="am-icon-trash"></i>删除</a>
				</div>
			</li>
		<%}%>
	</script>

	<script type="text/html" id="optionProvince">
		<%for(var i=0;i<data.length;i++){%>
			<option value="<%=data[i].id%>"><%=data[i].name%></option>
		
		<%}%>


	</script>
	<script type="text/html" id="optionCity">
		<option value="">市</option>
		<%for(var i=0;i<data.length;i++){%>
			<option value="<%=data[i].id%>"><%=data[i].name%></option>
		
		<%}%>


	</script>
	<script type="text/html" id="optionTown">
		<option value="">地方</option>
		<%for(var i=0;i<data.length;i++){%>
			<option value="<%=data[i].id%>"><%=data[i].name%></option>
		
		<%}%>


	</script>
	<script type="text/javascript" src="/Public/js/template-native.js"></script>
	<script type="text/javascript">
		function jsShow(){
			$(document).ready(function() {						
				$(".new-option-r").click(function() {
					$(this).parent('.user-addresslist').addClass("defaultAddr").siblings().removeClass("defaultAddr");
				});
				
				var $ww = $(window).width();
				if($ww>640) {
					$("#doc-modal-1").removeClass("am-modal am-modal-no-btn")
				}
				
			})
		}
		function getAddress(){
			$.get('/Api/Index/getAddress',null,function(ret){
						if (ret.status==true) {
							var html=template('showAddress',ret);
							$('.am-thumbnails').html("");
							$('.am-thumbnails').append(html);
							jsShow();
						}		
			})
		}
		getAddress();


		$.get('/Api/Index/addressSelect',{'fid':'0'},function(ret){
					if (ret.status==true) {
						var html=template('optionProvince',ret);
						$('#province').append(html);
					}
		})
		function citySelect(obj){
			var fid=$(obj).val();
			$.get('/Api/Index/addressSelect',{'fid':fid},function(ret){
					if (ret.status==true) {
						var html=template('optionCity',ret);
						$('#city').html("");
						$('#city').append(html);
					}
			})
		}
		function townSelect(obj){
			var fid=$(obj).val();
			$.get('/Api/Index/addressSelect',{'fid':fid},function(ret){
					if (ret.status==true) {
						var html=template('optionTown',ret);
						$('#town').html("");
						$('#town').append(html);
					}
			})
		}
		function addAddress(){
			
			var param={};
			 param.id=$('.am-form-horizontal').attr('alt');
			 param.name=$('.am-form-horizontal').find('#user-name').val();
			 param.phone=$('.am-form-horizontal').find('#user-phone').val();
			var province=$('.am-form-horizontal').find('#province').find('option:selected').text();
			var city=$('.am-form-horizontal').find('#city').find('option:selected').text();
			var town=$('.am-form-horizontal').find('#town').find('option:selected').text();
			var detailAddress=$('.am-form-horizontal').find('#user-intro').val();
			param.address=province+";"+city+";"+town+";"+detailAddress;
			$.post('/Api/Index/clientAddress',param,function(ret){
					
					$('.am-form-horizontal').find('#user-name').val("");
					$('.am-form-horizontal').find('#user-phone').val("");
					$('.am-form-horizontal').find('#user-intro').val("");
					alert("保存成功")	;
					})
			$('.am-form-horizontal').attr('alt',"");
			getAddress();
		}
		function delClick(obj){
			var id=$(obj).attr('alt');
			$.get('/Api/Index/deletAddress',{'id':id},function(ret){
					alert("删除成功")	;
			})
			getAddress();
			
		}
		function chaClick(obj){
			var id=$(obj).attr('alt');
			var name=$(obj).closest('.user-addresslist').find('.new-txt').text();
			var phone=$(obj).closest('.user-addresslist').find('.new-txt-rd2').text();
			var province=$(obj).closest('.user-addresslist').find('.province').text();
			var city=$(obj).closest('.user-addresslist').find('.city').text();
			var town=$(obj).closest('.user-addresslist').find('.dist').text();
			var street=$(obj).closest('.user-addresslist').find('.street').text();
			$('.am-form-horizontal').find('#user-name').val(name);
			$('.am-form-horizontal').find('#user-phone').val(phone);
			$('.am-form-horizontal').find('#user-intro').val(street);
			//$('select[name="province"]').find("option[value='1']").attr('selected',true);
			$('.am-form-horizontal').attr('alt',id);

		}
		function cencle(obj){				//取消
			$('.am-form-horizontal').attr('alt',"");
			$('.am-form-horizontal').find('#user-name').val("");
			$('.am-form-horizontal').find('#user-phone').val("");
			$('.am-form-horizontal').find('#user-intro').val("");

		}
		function default1(obj){
			var id=$(obj).attr('alt');
			$.get('/Api/Index/chanDefault',{'id':id},function(ret){

			})

		}

	</script>

	</body>

</html>
